# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
import logging

LOGGER = logging.getLogger('PySolFC.ViewLib.Image')

from ImageTk import PhotoImage as _PhotoImage
from ..utillib.image_pil import NPSImage as _AbstractImage, Image as _Image


class PilImage(_AbstractImage, _PhotoImage, object):
    """
    Abstract Image with PIL based methods for tk **PhotoImage**.
    """

    def __init__(self, image):  #, pil_image_orig=None):
        """
        __init__([image:Image, pil_image_orig:PilImage=None]) -> None
        Initialize PIL image.
        """
        super(_AbstractImage, self).__init__(image)
        self._orig_pil_image = self._pil_image = image

    @staticmethod
    def update_image(image):
        return PilImage(image)


def create_image(size, fill=None, outline=None, linewidth=1):
    """
    create_image(size:int, fill:str=None, outline:str=None, linewidth:int=1)
      -> PilImage

    Returns image of **size** with **fill** and **outline** for canvas. Size of
    **outline** is **linewidth**.
    """
    return PilImage.new_image(size, fill, outline, linewidth)


def load_image(path):
    """
    load_image(path:str=None) -> PilImage

    Returns image from **path**.
    """
    LOGGER.info('Load image: %s', path)
    return PilImage(_Image.open(path).convert('RGBA'))